home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fsattach / fsattach.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-13  |  5.4 KB  |  218 lines

  1. /*
  2.  * fsattach.h --
  3.  *
  4.  *    Declarations for fsattach.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/admin/fsattach/RCS/fsattach.h,v 1.7 91/01/12 16:48:54 jhh Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _FSATTACH
  19. #define _FSATTACH
  20.  
  21. #include <assert.h>
  22. #include <errno.h>
  23. #include <fs.h>
  24. #include <fsCmd.h>
  25. #include <host.h>
  26. #include <list.h>
  27. #include <option.h>
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <status.h>
  31. #include <stdlib.h>
  32. #include <sysStats.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <sys/file.h>
  36. #include <sys/wait.h>
  37. #include <disk.h>
  38.  
  39. /* constants */
  40.  
  41. /*
  42.  * Maximum limits on things.
  43.  */
  44. #define MAX_FIELD_LENGTH    256
  45. #define MAX_LINE_LENGTH        1024
  46. #define MAX_EXEC_ARGS        20
  47. #define MAX_PASS         10
  48.  
  49. /*
  50.  * Return codes from fscheck.
  51.  */
  52. #define FSCHECK_OK        (char) 0
  53. #define FSCHECK_SOFT_ERROR    (char) 1
  54. #define FSCHECK_OUT_OF_MEMORY    (char) 2
  55. #define FSCHECK_NOREBOOT    (char) 3
  56. #define FSCHECK_REBOOT        (char) 4
  57.  
  58. #define FSCHECK_HARD_ERROR    (char) -1
  59. #define FSCHECK_READ_FAILURE    (char) -2
  60. #define FSCHECK_WRITE_FAILURE    (char) -3
  61. #define FSCHECK_BAD_ARG        (char) -4
  62. #define FSCHECK_MORE_MEMORY    (char) -5
  63. #define FSCHECK_DISK_FULL    (char) -6
  64.  
  65. /*
  66.  * Return code from child process if the exec fails.
  67.  */
  68. #define EXEC_FAILED        (char) 32
  69.  
  70. /* 
  71.  * Exit codes.
  72.  */
  73. #define OK         0
  74. #define REBOOT        1
  75. #define HARDERROR     2
  76. #define SOFTERROR    3
  77. #define NOREBOOT    4
  78.  
  79. /* 
  80.  * Status of entry in mount table. Starts off as CHILD_OK, changes to 
  81.  * CHILD_RUNNING while fscheck is running. If fscheck completes ok, 
  82.  * then status changes back to CHILD_OK to indicate that the prefix should 
  83.  * be attached. Otherwise the status changes to CHILD_FAILURE.
  84.  */
  85. #define CHILD_OK    0
  86. #define CHILD_RUNNING    1
  87. #define CHILD_FAILURE    2
  88.  
  89.  
  90. /* data structures */
  91.  
  92.  
  93. /*
  94.  * Information stored about active child processes.
  95.  */
  96. typedef struct {
  97.     int        pid;        /* process id of child */
  98.     int        mountIndex;    /* index in mount table that child corresponds
  99.                  * to */
  100. } ChildInfo;
  101.  
  102. /*
  103.  * Used to build a linked list of arguments.
  104.  */
  105. typedef struct {
  106.     List_Links    links;        /* Used to make a list */
  107.     char    *arg;        /* Ptr to argument string */
  108. } ArgHeader;
  109.  
  110.  
  111. /*
  112.  * Information about arguments to fscheck. We build up a table of these
  113.  * for devices we haven't seen yet in the mount table. This allows "Arg"
  114.  * commands for a device to precede the "Attach" or "Export" command.
  115.  * Also arguments for "all" devices are kept in the table until the
  116.  * entire mount file is parsed.
  117.  */
  118. typedef struct {
  119.     char    source[MAX_FIELD_LENGTH];     /* name of device arguments
  120.                          * are for */
  121.     int        line;                /* line number of "args" cmd */
  122.     ArgHeader    argList;            /* list of arguments */
  123. } ArgInfo;
  124.  
  125. /* 
  126.  * Entry in the mount table.
  127.  */
  128. typedef struct {
  129.     char    source[MAX_FIELD_LENGTH];    /* name of source device or
  130.                          * prefix */
  131.     char     dest[MAX_FIELD_LENGTH];        /* name of destination prefix */
  132.     int        group;                /* check group of device */
  133.     Boolean    device;                /* TRUE => source is a device */
  134.     Boolean    export;                /* TRUE => export prefix */
  135.     Boolean    readonly;            /* TRUE => prefix should be
  136.                          * mounted as read only */
  137.     Boolean    doCheck;            /* device should be checked */
  138.     int        status;                /* status of this entry */
  139.     ArgInfo    argInfo;            /* arguments to fscheck */
  140.     Boolean    checked;            /* TRUE => fscheck was run */
  141. } MountInfo;
  142.  
  143. /*
  144.  * Used to store information about groups (disks that cannot be checked
  145.  * at the same time.
  146.  */
  147.  
  148. typedef struct {
  149.     char    name[MAX_FIELD_LENGTH];        /* name of group */
  150.     Boolean    running;            /* is there an fscheck
  151.                          * running for a device in
  152.                          * in this group? */
  153. } GroupInfo;
  154.  
  155. /*
  156.  * Used to allocate memory.
  157.  */
  158. #define Alloc(ptr,type, number, msg) { \
  159.     (ptr) = (type *) malloc((unsigned) (sizeof(type) * (number))); \
  160.     if ((ptr) == NULL) { \
  161.         (void) fprintf(stderr, "Out of memory: %s.\n",msg); \
  162.         (void) exit(HARDERROR); \
  163.     } \
  164.     }
  165.  
  166. /* 
  167.  * Handy comparison macros.
  168.  */
  169. #define min(a,b) (((a) < (b)) ? (a) : (b) )
  170. #define max(a,b) (((a) > (b)) ? (a) : (b) )
  171.  
  172. /*
  173.  * Global variables.
  174.  */
  175. extern char        *progName;
  176. extern int        mountTableSize;
  177. extern int        mountTableSizeIncrement;
  178. extern char        *tempOutputFile;
  179. extern char        *heapLimitString;
  180. extern int        tempOutputFileSize;
  181. extern char        *outputDir;
  182. extern Boolean        verbose;
  183. extern MountInfo    *mountTable;
  184. extern Boolean        printOnly;
  185. extern char        *fscheckPath;
  186. extern char        *bootPrefix;
  187. extern int        numGroups;
  188. extern GroupInfo    *groupInfo;
  189. extern int        groupInfoSize;
  190. extern int        groupInfoSizeIncrement;
  191. extern int        debug;
  192.  
  193. /*
  194.  * Global functions.
  195.  */
  196. extern    void        GetRecoveryInfo();
  197. extern    ReturnStatus    ParseMount();
  198. extern    ReturnStatus    CheckDisks();
  199. extern    void        CacheWriteBack();
  200. extern    ReturnStatus    RunChild();
  201. extern    void        StartExec();
  202. extern    void        AddExecArgs();
  203. extern    int        DoExec();
  204. extern    void        MoveRootOutput();
  205. extern    ReturnStatus    ParseConfig();
  206. extern  void        Prefix();
  207. extern  void        PrintFscheckError();
  208. extern    void        AddList();
  209. extern    void        MergeList();
  210. extern    void        DeleteList();
  211. extern  void        PreloadPrefixTable();
  212. extern    char        *GetAttachName();
  213. extern void        bzero();
  214. extern int        exit();
  215.  
  216. #endif /* _FSATTACH */
  217.  
  218.